package leetcode.code2225;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import leetcode.IDebug;

public class Solution1 implements IDebug {

	public List<List<Integer>> findWinners(int[][] matches) {
		Map<Integer, Integer> wins = new HashMap<>();
		Map<Integer, Integer> losts = new HashMap<>();

		for (int i = 0; i < matches.length; i++) {
			int[] cur = matches[i];
			int win = cur[0], lost = cur[1];
			wins.put(win, wins.getOrDefault(wins, 0) + 1);
			losts.put(lost, losts.getOrDefault(lost, 0) + 1);
		}
		List<Integer> winners = new ArrayList<>();
		for (Map.Entry<Integer, Integer> win : wins.entrySet()) {
			if (!losts.containsKey(win.getKey())) {
				winners.add(win.getKey());
			}

		}
		List<Integer> losers = new ArrayList<>();
		for (Map.Entry<Integer, Integer> lost : losts.entrySet()) {
			if (lost.getValue() == 1) {
				losers.add(lost.getKey());
			}
		}
		Collections.sort(winners);
		Collections.sort(losers);
		List<List<Integer>> ans = new ArrayList<>();
		ans.add(winners);
		ans.add(losers);
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
